#include <iostream>
#include <string.h>
using namespace std;

class Jerry{

private:
    int id;
    char *name;
    char *loveToEat;

public:

    Jerry(){
        id = -1;
        name = loveToEat = nullptr;
    }

    Jerry(int id, char *n, char *love = nullptr): id(id){
        gao(n, love);
    }

    void gao(char *n, char *love){
        name = new char[strlen(n) + 1];
        strcpy(name, n);
        if(love){
            loveToEat = new char[strlen(love) + 1];
            strcpy(loveToEat, love);
        }else{
            loveToEat = nullptr;
        }
    }

    void operator = (const Jerry &jerry){
        id = jerry.id;
        gao(jerry.name, jerry.loveToEat);
    }

    char *getName() const{
        return name;
    }

    char *getLoveToEat() const {
        return loveToEat;
    }

    int getId() const {
        return id;
    }

    ~Jerry(){
        delete name;
        delete loveToEat;
    }
};

class Tom{

private:
    int size;
    char *name;
    Jerry targets[10];

public:
    Tom(char *n){
    	size = 0;
        name = new char[strlen(n) + 1];
        strcpy(name, n);
    }

    void addTarget(Jerry &jerry) {
        targets[size++] = jerry;
    }

    void caught(char *name){
        for(int i = 0; i < size; ++i){
            if(strcmp(targets[i].getName(), name) == 0){
                targets[i] = targets[--size];

                break;
            }
        }
    }

    void caught(int id){
        for(int i = 0; i < size; ++i){
            if(targets[i].getId() == id){
                targets[i] = targets[--size];
                break;
            }
        }
    }

    void printTargets() {
        printf("%s\'s Targets: \n", name);
        if(size == 0){
            printf("Empty\n\n");
        }else{

            for(int i = 0; i < size; ++i){
                printf("id: %d  name: %s  loveToEat: %s\n", targets[i].getId(), targets[i].getName(), targets[i].getLoveToEat());
            }
            printf("\n");
        }
    }

    ~Tom(){
        delete name;
    }
};

int main(){
    Jerry jerry1(1, "Jerry1", "Cheese");
    Jerry jerry2(2, "Jerry2", "Cake");
    Jerry jerry3(3, "Jerry3");
    Jerry jerry4(4, "Jerry4", "Coffee");

    Tom tom1("Tom1"), tom2("Tom2");
    tom1.addTarget(jerry1);
    tom1.addTarget(jerry2);
    tom1.addTarget(jerry3);
    tom1.printTargets();
    
    tom2.addTarget(jerry4);
    tom2.printTargets();

    tom1.caught(3);
    tom1.caught("Jerry2");
    tom2.caught(4);

    tom1.printTargets();
    tom2.printTargets();

    return 0;
}